export function getDataType(data,reolve=false) {
    const type= Object.prototype.toString.call(data);
    if(reolve){
        if(type.includes(`String`)&&data.trim()!==''){
            if(!isNaN(data)){
                return Object.prototype.toString.call(parseFloat(data));
            }
        }
    }
    return type
}

export function myTimeOut(time=1000){
    return new Promise(res=>{
        setTimeout(()=>{
            return res();
        },time)
    })
}

export function deepClone(obj) {
    let newObj = Array.isArray(obj) ? [] : {}
    if (obj && typeof obj === "object") {
        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                newObj[key] = (obj && typeof obj[key] === 'object') ? deepClone(obj[key]) : obj[key];
            }
        }
    } 
    return newObj
}

export function checkMoneyAmount(amount){
    if(isNaN(amount)||amount==''){
        return {
            errCode: 0,
            myErrCode: 10000,
            errMsg: '请输入正确的金额，最多小数点两位'
        }
    }
    const num_amount= parseFloat(amount);
    if(!/^\d+(\.\d{1,2})?$/.test(num_amount+'')){
        return {
            errCode: 0,
            myErrCode: 10001,
            errMsg: '请输入正确的金额，最多小数点两位'
        }
    }
    if(num_amount<=0){
        return {
            errCode: 0,
            myErrCode: 10002,
            errMsg: '输入金额必须大于零，请重试'
        }
    }
    return {
        errCode: 0,
        myErrCode: 0,
        data:{
            amount:num_amount
        }
    }
}

export function showModalDbError(results){
    uni.showModal({
        title: `异常提示`,
        showCancel: false,
        content:results.errMsg
    });
}